<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
 Overview
</title>
<link rel ="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="XmlDom.jsc Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="../index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="../overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="../allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>XmlDom.jsc</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		js.net.XmlDom class http://jsvm.homolo.com/jsvm2.0/docs/api/
 <BR/><BR/><B>Version: </B>2.01, 10/23/05
 <BR/><BR/><B>Author:</B> DSONET, Wan Changhua
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="XmlDom.html">js.net.XmlDom</a></b></td>
    <td>This is the xmldom utility class.</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"># language: JSVM2

<span class="comment">/**
 * <span class="attrib">@fileoverview</span> js.net.XmlDom class http://jsvm.homolo.com/jsvm2.0/docs/api/
 * <span class="attrib">@file</span>		XmlDom.jsc
 * <span class="attrib">@author</span>	DSONET, Wan Changhua
 * <span class="attrib">@version</span>	2.01, 10/23/05
 * <span class="attrib">@since</span>		JSVM2.0
 */</span>
 

package js.net;

import js.lang.NotSupportException;
import js.lang.System;

<span class="comment">/**
 * Create a new XmlDom instance.
 * Inherit from JObject
 * <span class="attrib">@author</span>	DSONET, Wan Changhua
 * <span class="attrib">@version</span>	2.01, 10/23/05
 * <span class="attrib">@extends</span> JObject
 * <span class="attrib">@class</span> This is the xmldom utility class.
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@throws</span> NotSupportException if current browser does not support XMLDOM/document.implementation.createDocument().
 * <span class="attrib">@return</span>  a &lt;code&gt;Document&lt;/code&gt; by document.implementation.createDocument() if the current browser is moz.
 *          a &lt;code&gt;Microsoft.XMLDOM&lt;/code&gt; instance otherwise.
 */</span>
<span class="reserved">function</span> XmlDom()
{
	<span class="reserved">if</span> (js.lang.System.isMozBrowser())
	{
			var doc = document.implementation.createDocument(<span class="literal">""</span>, <span class="literal">""</span>, null);
			<span class="comment">// some versions of Moz do not support the readyState property</span>
			<span class="comment">// and the onreadystate event so we patch it!</span>
			<span class="reserved">if</span> (doc.readyState == null)
			{
				doc.readyState = 1;
				doc.addEventListener(<span class="literal">"load"</span>, <span class="reserved">function</span> () {
					doc.readyState = 4;
					<span class="reserved">if</span> (typeof doc.onreadystatechange == <span class="literal">"function"</span>)
					{
						doc.onreadystatechange();
					}
				}, false);
			}

			<span class="reserved">return</span> doc;
	}
	<span class="reserved">else</span>
	{
		<span class="reserved">if</span> (progId != null)
		{
			<span class="reserved">return</span> new ActiveXObject(progId);
		}
		<span class="reserved">for</span> (var i = 0; i &lt; progIds.length; i++)
		{
			try
			{
				var obj = new ActiveXObject(progIds[i]);
				progId = progIds[i];
				<span class="reserved">return</span> obj;
			}
			catch (ex) { }
		}
	}
	throw new js.lang.NotSupportException(
		<span class="literal">"Can't create XmlDom object under '"</span>
		+ System.getPlatform()	+ <span class="literal">"'!"</span>);
}


<span class="comment">/**
 * Retrieves a new XmlDom instance.
 * <span class="attrib">@returns</span>  a &lt;code&gt;Microsoft.XMLDOM&lt;/code&gt; instance if the current browser is ie5.
 *          a &lt;code&gt;XmlDom&lt;/code&gt; instance otherwise.
 * <span class="attrib">@type</span> XmlHttp
 */</span>
XmlDom.create = <span class="reserved">function</span> ()
{
	<span class="reserved">return</span> (System.getPlatform() == <span class="literal">"ie5"</span>) ?
		new ActiveXObject(<span class="literal">"Microsoft.XMLDOM"</span>) : new XmlDom();
}


<span class="comment">/**
 * <span class="attrib">@private</span>
 */</span>
var progIds = [<span class="literal">"MSXML2.DOMDocument"</span>, <span class="literal">"Microsoft.XMLDOM"</span>, <span class="literal">"MSXML.DOMDocument"</span>, <span class="literal">"MSXML3.DOMDocument"</span>];

<span class="comment">/**
 * <span class="attrib">@private</span>
 */</span>
var progId = null;


<span class="reserved">if</span> (js.lang.System.isMozBrowser() &amp;&amp; 
	window.DOMParser &amp;&amp;	
	window.XMLSerializer &amp;&amp;
	window.Node)
{

	<span class="comment">// TODO</span>
	<span class="comment">// XmlDom did not extend the Document interface in some versions</span>
	<span class="comment">// of Mozilla. Extend both!</span>
	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
	XmlDom.<span class="reserved">prototype</span>.loadXML =
		Document.<span class="reserved">prototype</span>.loadXML = <span class="reserved">function</span> (s)
	{
		<span class="comment">// parse the string to a new doc</span>
		var doc2 = (new DOMParser()).parseFromString(s, <span class="literal">"text/xml"</span>);
		<span class="comment">// remove all initial children</span>
		<span class="reserved">while</span> (<span class="reserved">this</span>.hasChildNodes())
		{
			<span class="reserved">this</span>.removeChild(<span class="reserved">this</span>.lastChild);
		}
		<span class="comment">// insert and import nodes</span>
		<span class="reserved">for</span> (var i = 0; i &lt; doc2.childNodes.length; i++)
		{
			<span class="reserved">this</span>.appendChild(<span class="reserved">this</span>.importNode(doc2.childNodes[i], true));
		}
		try
		{
			doc2.childNodes[0].xml;
			<span class="reserved">return</span> true;
		}
		catch (ex)
		{
			<span class="reserved">return</span> false;
		}
	};

	<span class="comment">/*
	 * xml getter
	 *
	 * This serializes the DOM tree to an XML String
	 *
	 * Usage: var sXml = oNode.xml
	 *
	 */</span>

	<span class="comment">/**
	 * XmlDom did not extend the Document interface in some versions
	 * of Mozilla. Extend both!
	 * <span class="attrib">@ignore</span>
	 */</span>
	XmlDom.<span class="reserved">prototype</span>.__defineGetter__(<span class="literal">"xml"</span>, <span class="reserved">function</span> ()
		{
			<span class="reserved">return</span> <span class="literal">"&lt;?xml version=\"</span>1.0\<span class="literal">"?&gt;"</span> 
				+ (new XMLSerializer()).serializeToString(<span class="reserved">this</span>);
		});

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
	Document.<span class="reserved">prototype</span>.__defineGetter__(<span class="literal">"xml"</span>, <span class="reserved">function</span> ()
		{
			<span class="reserved">return</span> <span class="literal">"&lt;?xml version=\"</span>1.0\<span class="literal">"?&gt;"</span> 
				+ (new XMLSerializer()).serializeToString(<span class="reserved">this</span>);
		});

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
	XmlDom.<span class="reserved">prototype</span>.createNode = <span class="reserved">function</span> (stype, name, ns)
	{
        switch (stype)
        {
            case 1 :
                <span class="reserved">return</span> (ns == null || ns == <span class="literal">""</span>) ? <span class="reserved">this</span>.createElement(name)
                	: <span class="reserved">this</span>.createElementNS(ns, name);
            case 2 :
            		<span class="reserved">return</span> (ns == null || ns == <span class="literal">""</span>) ? <span class="reserved">this</span>.createAttribute(name)
                	: <span class="reserved">this</span>.createAttributeNS(ns, name);
            case 3 :
            default :
                <span class="reserved">return</span> <span class="reserved">this</span>.createTextNode(<span class="literal">""</span>);
        }
   }

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  XmlDom.<span class="reserved">prototype</span>.__realLoad = XmlDom.<span class="reserved">prototype</span>.load;
  
  <span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  XmlDom.<span class="reserved">prototype</span>.load = <span class="reserved">function</span>(uri)
  {
      <span class="reserved">this</span>.readyState = 0;
      <span class="reserved">this</span>.__realLoad(uri);
  }

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  XmlDom.<span class="reserved">prototype</span>.__defineSetter__(<span class="literal">"onreadystatechange"</span>, <span class="reserved">function</span> (f)
		{
			<span class="reserved">if</span> (<span class="reserved">this</span>._onreadystatechange)
			{
				<span class="reserved">this</span>.removeEventListener(<span class="literal">"load"</span>,<span class="reserved">this</span>._onreadystatechange,false);
			}
			<span class="reserved">this</span>._onreadystatechange = f;
			<span class="reserved">if</span> (f)
			{
          <span class="reserved">this</span>.addEventListener(<span class="literal">"load"</span>, f, false);
      }
      <span class="reserved">return</span> f;
		});

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  XmlDom.<span class="reserved">prototype</span>.__defineGetter__(<span class="literal">"onreadystatechange"</span>, <span class="reserved">function</span> ()
  	{
			<span class="reserved">return</span> <span class="reserved">this</span>._onreadystatechange;
		});

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  XmlDom._mozHasParseError = <span class="reserved">function</span> (oDoc)
  {
      <span class="reserved">return</span> (!oDoc.documentElement) ||
      	oDoc.documentElement.localName == <span class="literal">"parsererror"</span>
      		&amp;&amp; oDoc.documentElement.getAttribute(<span class="literal">"xmlns"</span>) ==
      			<span class="literal">"http://www.mozilla.org/newlayout/xml/parsererror.xml"</span>;
  }

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  XmlDom.<span class="reserved">prototype</span>.__defineGetter__(<span class="literal">"parseError"</span>, <span class="reserved">function</span> ()
  	{
			var hasError = XmlDom._mozHasParseError(<span class="reserved">this</span>);
			var res = {errorCode:0, filepos:0, line:0, linepos:0, reason:<span class="literal">""</span>, srcText:<span class="literal">""</span>, url:<span class="literal">""</span>};
			<span class="reserved">if</span> (hasError)
			{
				res.errorCode= -1;
				try
				{
					res.srcText = <span class="reserved">this</span>.getElementsByTagName(<span class="literal">"sourcetext"</span>)[0].firstChild.data;
					res.srcText = res.srcText.replace(/\n\-\^$/, <span class="literal">""</span>);
				}
				catch (ex)
				{
					res.srcText = <span class="literal">""</span>;
				}
				try
				{
					var s = <span class="reserved">this</span>.documentElement.firstChild.data;
					var re = /XML Parsing Error\:(.+)\nLocation\:(.+)\nLine Number(\d+)\,Column(\d+)/;
					var a = re.exec(s);
					res.reason = a[1];
					res.url=a[2];
					res.line=a[3];
					res.linepos=a[4];
				}
				catch (ex)
				{
					res.reason = <span class="literal">"uknown"</span>;
				}
			}
			<span class="reserved">return</span> res;
		});

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  Node.<span class="reserved">prototype</span>.__defineGetter__(<span class="literal">"xml"</span>, <span class="reserved">function</span> ()
  	{
			<span class="reserved">return</span>(new XMLSerializer).serializeToString(<span class="reserved">this</span>);
		});

	<span class="comment">/**
	 * <span class="attrib">@ignore</span>
	 */</span>
  Attr.<span class="reserved">prototype</span>.__defineGetter__(<span class="literal">"xml"</span>, <span class="reserved">function</span> ()
  	{
			var nv = (new XMLSerializer).serializeToString(<span class="reserved">this</span>);
			<span class="reserved">return</span> <span class="reserved">this</span>.nodeName + <span class="literal">"=\"</span><span class="literal">"
				+ nv.replace(/\"</span>/g,<span class="literal">"&amp;quot;"</span>) + <span class="literal">"\"</span><span class="literal">";
		});

	/**
	 * @ignore
	 */
  Node.prototype.__defineGetter__("</span>baseName<span class="literal">", function ()
  	{
			var lParts = this.nodeName.split("</span>:<span class="literal">");
			return lParts[lParts.length - 1];
		});

	/**
	 * @ignore
	 */
  Text.prototype.__defineGetter__("</span>text<span class="literal">", function ()
		{
			return this.nodeValue;
		});

	/**
	 * @ignore
	 */
  Node.prototype.__defineGetter__("</span>text<span class="literal">", function ()
  	{
			var cs = this.childNodes;
			var l = cs.length;
			var sb = new Array(l);
			for (var i = 0; i &lt; l; i++)
			{
				sb[i] = cs[i].text;
			}
			return sb.join("</span><span class="literal">");
		});

	/**
	 * @ignore
	 */
  Node.prototype.selectNodes = function (sExpr)
  {
		var doc = (this.nodeType == 9) ? this : this.ownerDocument;
		var nsRes = doc.createNSResolver(this.nodeType == 9 ? this.documentElement : this);
		var nsRes2;
		if (doc._selectionNamespaces)
		{
			nsRes2 = function(s){
				return doc._selectionNamespaces[s] || nsRes.lookupNamespaceURI(s);
			}
		}
		else
		{
			nsRes2 = nsRes;
		}
		var xpRes = doc.evaluate(sExpr, this, nsRes2, 5, null);
		var res = [];
		var item;
		while (item = xpRes.iterateNext())
		{
			res.push(item);
		}
		return res;
  }

	/**
	 * @ignore
	 */
  Node.prototype.selectSingleNode = function (sExpr)
  {
		var doc = (this.nodeType == 9) ? this : this.ownerDocument;
		var nsRes = doc.createNSResolver((this.nodeType == 9) ? this.documentElement : this);
		var nsRes2;
		if (doc._selectionNamespaces)
		{
			nsRes2 = function (s)
			{
				return doc._selectionNamespaces[s] || nsRes.lookupNamespaceURI(s);
			};
		}
		else
		{
			nsRes2 = nsRes;
		}
		var xpRes = doc.evaluate(sExpr, this, nsRes2, 9, null);
		return xpRes.singleNodeValue;
  }

	/**
	 * @ignore
	 */
  Node.prototype.transformNode = function (oXsltNode)
  {
		var doc = (this.nodeType == 9) ? this : this.ownerDocument;
		var processor = new XSLTProcessor();
		processor.importStylesheet(oXsltNode);
		var df = processor.transformToFragment(this, doc);
		return df.xml;
  }

	/**
	 * @ignore
	 */
  Node.prototype.transformNodeToObject = function (oXsltNode, oOutputDocument)
  {
		var doc = (this.nodeType == 9) ? this : this.ownerDocument;
		var outDoc = (oOutputDocument.nodeType == 9) ? oOutputDocument :
			oOutputDocumentOutputDocument.ownerDocument;
		var processor = new XSLTProcessor();
		processor.importStylesheet(oXsltNode);
		var df = processor.transformToFragment(this, doc);
		while (oOutputDocument.hasChildNodes())
		{
			oOutputDocument.removeChild(oOutputDocument.lastChild);
		}
		var cs = df.childNodes;
		var l = cs.length;
		for(var i = 0; i &lt; l; i++)
		{
			oOutputDocument.appendChild(outDoc.importNode(cs[i], true));
		}
  }

	/**
	 * @ignore
	 */
  XmlDom.prototype.setProperty = function(sName, sValue)
  {
		if (sName == "</span>SelectionNamespaces<span class="literal">")
		{
			this._selectionNamespaces = {};
			var parts = sValue.split(/\s+/);
			var re = /^xmlns\:([^=]+)\=((\"</span>([^\<span class="literal">"]*)\"</span>)|(\<span class="literal">'([^\'</span>]*)\'))$/;
			<span class="reserved">for</span> ( var i = 0; i &lt; parts.length; i++)
			{
				re.test(parts[i]);
				<span class="reserved">this</span>._selectionNamespaces[RegExp.$1] = RegExp.$4 || RegExp.$6;
			}
		}
  }

}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="../index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="../overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="../allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Nov 17 20:10:21 2005</div>
</body>
</html>
